#include <chrono>
#include "PushBoxGame.h"
static char* stepTab[] = {"^","<","none",">","v"};
int main(int argc, char* argv[]) {
    std::vector<std::vector<std::vector<char>>> grids;
    std::vector<std::string> titles;
    LoadLevelsFromFile(argv[1],grids, titles);
    std::vector<int> cnts;
    long long timeMax = 0;
    int timeMaxK = 0;
    for(int k = 0; k < grids.size(); ++k)
    {
        std::cout << "Level " << k <<"--"<<titles[k]<< std::endl;
        printGame(grids[k]);
        std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
        MapInfo mapInfo;
        State state;
        auto grid = getMap(grids[k], state, mapInfo);
        auto  solution = SolvePushBox(state,grid,mapInfo);
        std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();
        auto duration = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count();
        if(timeMax < duration/1000) {
            timeMax = duration / 1000;
            timeMaxK = k;
        }
        if(solution.empty())
        {
            std::cout<<"can not find solution, time cost: "<<duration/1000<<" ms"<<std::endl;
            cnts.emplace_back(k);
        }else{
            std::cout<<"find solution, time cost: "<<duration/1000<<" ms "<<solution.size()<<" steps"<<std::endl;
            for(int i = 0; i < solution.size(); ++i)
            {
                std::cout<<stepTab[solution[i].dx+solution[i].dy*2+2];
            }
            std::cout<<std::endl;
            std::cout<<"max time cost: "<<timeMax<<" ms in level "<<timeMaxK<<std::endl;
        }
        // 统计信息
        std::cout<<cnts.size()<<" levels not found solution ";
        for(int cnt : cnts)
        {
            std::cout<<cnt<<",";
        }
        std::cout<<std::endl;
    }
    return 0;
}
